using Microsoft.EntityFrameworkCore;
using UniversalAdmin.Domain.Entities;
using UniversalAdmin.Domain.Repositories;
using UniversalAdmin.Infrastructure.Data.Contexts;

namespace UniversalAdmin.Infrastructure.Repositories;

public class DocumentChunkRepository : Repository<DocumentChunk>, IDocumentChunkRepository
{
    public DocumentChunkRepository(ApplicationDbContext context) : base(context)
    {
    }

    public async Task<IEnumerable<DocumentChunk>> GetByDocumentIdAsync(Guid documentId)
    {
        return await _context.DocumentChunks
            .Where(dc => dc.DocumentId == documentId)
            .ToListAsync();
    }

    public async Task<IEnumerable<DocumentChunk>> GetAllWithDocumentAsync()
    {
        return await _context.DocumentChunks
            .Include(dc => dc.Document)
            .ToListAsync();
    }

    public async Task<IEnumerable<DocumentChunk>> GetAllByUserIdAsync(Guid userId)
    {
        return await _context.DocumentChunks
            .Include(dc => dc.Document)
            .Where(dc => dc.Document.UploadedBy == userId)
            .ToListAsync();
    }
}